home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / human interface toolbox / powermacor68k / powermacor68k.c next >
Encoding:
C/C++ Source or Header  |  2000-06-23  |  2.8 KB  |  92 lines

  1. /*
  2.     File:        PowerMacOr68K.c
  3.  
  4.     Contains:    This snippet shows how to determine whether you are running on
  5.                 a Power Macintosh or on a 680x0 Macintosh.  It also provides the
  6.                 method for determine exactly which type of processor is running.
  7.                 This works around an off-by-one error with gestaltNativeCPUType.
  8.  
  9.     Written by: Virginia (Ginny) McCulloh    
  10.  
  11.     Copyright:    Copyright © 1995-1999 by Apple Computer, Inc., All Rights Reserved.
  12.  
  13.                 You may incorporate this Apple sample source code into your program(s) without
  14.                 restriction. This Apple sample source code has been provided "AS IS" and the
  15.                 responsibility for its operation is yours. You are not permitted to redistribute
  16.                 this Apple sample source code as "Apple sample source code" after having made
  17.                 changes. If you're going to re-distribute the source, we require that you make
  18.                 it clear in the source that the code was descended from Apple sample source
  19.                 code, but that you've made changes.
  20.  
  21.     Change History (most recent first):
  22.                 8/9/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  23.                                             Updated to list G3 750
  24.                 
  25.  
  26. */
  27.  
  28.  
  29. #include <Gestalt.h>
  30. #include <stdio.h>
  31.  
  32. Boolean    hasPowerPCArch(void);
  33.  
  34. void main()
  35. {
  36.     OSErr    err;
  37.     long    feature;
  38.  
  39.     /* First we will check the system architecture. */
  40.     if (hasPowerPCArch())    /* It's a Power Macintosh of some sort */
  41.     {
  42.         /* What kind of Power Macintosh processor is this. */
  43.         err = Gestalt (gestaltNativeCPUtype, &feature);
  44.         if (0x100 & feature)    
  45.         {
  46.             if (gestaltCPU601 == feature)
  47.                 printf( "\nThis puppy is a PowerMac with a 601 processor!");
  48.             else if (gestaltCPU603 == feature)
  49.                 printf( "\nThis puppy is a PowerMac with a 603 processor!");
  50.             else if (gestaltCPU604 == feature)
  51.                 printf( "\nThis puppy is a PowerMac with a 604 processor!");
  52.             else if (gestaltCPU750 == feature)
  53.                 printf( "\nThis puppy is a PowerMac with a G3 processor aka PPC 750!");
  54.             else
  55.                 printf( "\nThis must be some sort of PowerMac.  I think.");
  56.         }
  57.     }
  58.     else                    /* This is some sort of 68K machine */
  59.     {
  60.         err = Gestalt ( gestaltProcessorType, &feature );
  61.         if (gestalt68040 == feature)
  62.             printf( "\nThis is a 68040." );
  63.         else if (gestalt68030 == feature)
  64.             printf( "\nThis is a 68030.");
  65.         else if (gestalt68020 == feature)
  66.             printf( "\nThis is a 68020.");
  67.         else if (gestalt68010 == feature)
  68.             printf( "\nThis is a 68010.");
  69.         else if (gestalt68000 == feature)
  70.             printf( "\nThis is a 68000.");
  71.         else
  72.             printf( "\nI don't know what this is.");
  73.         
  74.     }
  75. }
  76.  
  77. Boolean    hasPowerPCArch()
  78. /* 
  79.     Gestalt will return an error if the gestaltSysArchitecture selector is
  80.     not recognized by the System, so we can assume this is a 68K machine.
  81.     Otherwise, this function returns true for a Power Mac and false for
  82.     a 68K Mac.
  83. */
  84. {
  85.     long    gestaltResult;
  86.  
  87.     if (Gestalt(gestaltSysArchitecture, &gestaltResult))
  88.         return(false);
  89.     else
  90.         return(gestaltResult == gestaltPowerPC);
  91. }
  92.